package com.xiaolin.admin.controller;

import com.xiaolin.admin.annotations.HasApi;
import com.xiaolin.admin.constants.ApiPermConstant;
import com.xiaolin.admin.model.dto.SysOrganizationTree;
import com.xiaolin.admin.model.entity.SysOrganization;
import com.xiaolin.admin.service.SysOrganizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaolin
 * @description 描述
 * @since 2024/7/12
 */
@Api("组织架构资源")
@RestController
@RequestMapping("/organization")
public class SysOrganizationController {

    @Autowired
    private SysOrganizationService organizationService;

    @HasApi(ApiPermConstant.COMMON_PERM)
    @ApiOperation("获取组织架构树")
    @PostMapping("/getTree")
    public List<SysOrganizationTree> getOrgTree(@RequestBody SysOrganization organization) {
        return organizationService.getOrgTree(organization);
    }

    @HasApi({"org:add"})
    @ApiOperation("添加组织架构")
    @PostMapping("/add")
    public boolean addOrg(@RequestBody SysOrganization organization) {
        return organizationService.addOrg(organization);
    }

    @HasApi({"org:get"})
    @ApiOperation("获取组织架构")
    @PostMapping("/get/{id}")
    public SysOrganization getOrg(@PathVariable("id") Integer id) {
        return organizationService.getOrg(id);
    }

    @HasApi({"org:update"})
    @ApiOperation("修改组织架构")
    @PostMapping("/update")
    public boolean updateOrg(@RequestBody SysOrganization organization) {
        return organizationService.updateOrg(organization);
    }

    @HasApi({"org:del"})
    @ApiOperation("删除组织架构")
    @PostMapping("/delete/{id}")
    public boolean deleteOrg(@PathVariable Integer id) {
        return organizationService.deleteOrg(id);
    }
}
